package com.trf.fm1;

/**
 * @author 小小唐
 * @Date 2022/9/20-星期二-11:12
 *
 *枚举算法实现
 * 求得到学生最可能得人数以及就业人数
 */
public class StuEnum {

    public static void main(String[] args) {
        StuEnum stuEnum = new StuEnum();
        stuEnum.calcByEnum(300,20,0.8323f);
    }

    public void calcByEnum(int iNum,int iOff,float fPercent){
        float fMinDiff = 1.0f,fTmp; //
        int iRealNum = 300; // iRealNum = 学生总人数
        for (int i=iNum-iOff+1;i <= iNum+iOff;i++){ // i=iNum-iOff+1是获取i的起始值，i<=iNum+iOff是得到i的最大值
            fTmp = Math.abs(Math.round(i*fPercent)/(float)i-fPercent);
            if (fTmp<fMinDiff){
                fMinDiff = fTmp;
                iRealNum = i;
            }
        }

        int iJiuYe = Math.round(iRealNum*fPercent);
        System.out.println("通过枚举，计算出学生总人数是："+iRealNum);
        System.out.println("已就业学生人数："+iJiuYe);
        System.out.println("问题陈述给出的就业率是："+fPercent*100+"%");
        System.out.println("计算结果对应的就业率是："+(iJiuYe/(float)iRealNum)*100+"%");

    }

}
